import Vue from 'vue'
import Router from 'vue-router'
import NodeFactory from '@/pages/index.vue'
import Home from '@/pages/home.vue'

import ErrorPage from '@/pages/error.vue'
import $ from '@/common'
Vue.use(Router)

var router = {
  mode: 'history',
  routes: [{
    path: '/',
    name: 'index',
    component: Home,
    beforeEnter(to, from, next) {
      next({ path: $.indexCode ? `/page/${$.indexCode}` : null })
    }
  }, {
    path: '/page/:node/:tab?',
    name: 'page',
    component: NodeFactory,
    beforeEnter(to, from, next) {
      next()
    }
  }, {
    path: '/*',
    name: 'error',
    component: ErrorPage
  }]
}
export default new Router(router)
